function login(req, res,app,session){
    console.log('in login');
    var userBean = require('../been/user').userBean;
    var db = require('../db').db;
    var userModel = db.model('users',userBean);

    var params = {};
    var errors = {}
    var body = req.body;

    if(body.id){
        params['userId'] = body.id;
    }else{
        res.send(JSON.stringify({err:'用户名不能为空'}));
        return;
    }
    if(body.pwd){
        params['pwd'] = body.pwd;
    }else{
        res.send(JSON.stringify({err:'密码不能为空'}));
        return;
    }
    userModel.find(params,function(err,results){
        if(err){
            res.send(err);
            console.error(err);
        }else if(results.length > 0){
            var user = results[0];
            var token = new Buffer(user.id + (new Date().getTime())).toString('base64');
            console.log(token);
            app.use(session({
                secret: token,//与cookieParser中的一致
                resave: true,
                saveUninitialized:true
            }));
            res.send(JSON.stringify({token:token}));
        }else{
            res.send(JSON.stringify({err:'用户名密码错误'}));
        }
    });

}
exports.run = login;